package com.demo.demo.jinhua;

/**
 * Copyright
 *
 * @Author WuHuang
 * @Date 2022/7/8
 */

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * 玩家基本信息类
 * @author lzq31
 *
 */
public class Player {
    /**
     * 定义一个玩家信息数据库
     */
    public static Map<String,Player> PLAYERS = new HashMap();
    static {
        for (int i = 0; i < 20; i++) {
            int num = i + 1;
            String numCode = num < 10 ? "0" + num : num + "";
            String playerName = "PLAYER" + numCode;
            PLAYERS.put(playerName, new Player(playerName));
        }
    }

    private String playerName; // 玩家的账号
    private int score; // 玩家的积分
    private List gameLogs = new ArrayList(); // 玩家的游戏日志
    public String getPlayerName() {
        return playerName;
    }
    public void setPlayerName(String playerName) {
        this.playerName = playerName;
    }
    public int getScore() {
        return score;
    }
    public void setScore(int score) {
        this.score = score;
    }
    public List getGameLogs() {
        return gameLogs;
    }
    public void setGameLogs(List gameLogs) {
        this.gameLogs = gameLogs;
    }

    public Player() {
        super();
    }

    /**
     * 根据账号名生成一个玩家对象
     * @param playerName
     */
    public Player(String playerName) {
        super();
        this.playerName = playerName;
    }

    @Override
    public String toString() {
        return this.playerName;
    }

// shift + alt + s 唤醒Source菜单
// ctrl + shift + o 全部引入需要导出的包

    public static void main(String[] args) {
// 获取Map中的KeySet对象
        Set keySet = Player.PLAYERS.keySet();
// 创建KeySet的迭代器
        Iterator it = keySet.iterator();
// 通过迭代器循环KeySet
        while (it.hasNext()) {
// 获取Key值
            String key = it.next().toString();
// 通过Map.get(key)方法获取对象key的value值
            Player value = (Player)Player.PLAYERS.get(key);
// 打印输出对象，默认会调用对象的toString()方法
            System.out.println(value);
        }
    }
}



